/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */
/**
 * Licensee: nu uc
 * License Type: Evaluation
 */
package org.testis.orm.classes;

import org.orm.*;

public class T_test_designtree {

    public T_test_designtree() {
    }

    public boolean save() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .saveObject(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean delete() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .deleteObject(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean refresh() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .getSession().refresh(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean evict() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .getSession().evict(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean deleteAndDissociate() throws PersistentException {
	try {
	    if (getParent() != null) {
		getParent().t_test_designtree.remove(this);
	    }

	    if (getClone() != null) {
		if (getClone().t_test_designtree1.contains(this)) {
		    getClone().t_test_designtree1.remove(this);
		} else {
		    System.out.println("original:" + getClone().getId()
			    + " does not contain clone:" + this.getId());
		}
	    }

	    org.testis.orm.classes.T_test_designtree[] lT_test_designtrees = t_test_designtree
		    .toArray();
	    for (int i = 0; i < lT_test_designtrees.length; i++) {
		lT_test_designtrees[i].setParent(null);
	    }
	    org.testis.orm.classes.T_test_designtree[] lT_test_designtree1s = t_test_designtree1
		    .toArray();
	    for (int i = 0; i < lT_test_designtree1s.length; i++) {
		lT_test_designtree1s[i].setClone(null);
	    }
	    org.testis.orm.classes.T_test_designtree_parameter_values[] lT_test_designtree_parameter_valuess = t_test_designtree_parameter_values
		    .toArray();
	    for (int i = 0; i < lT_test_designtree_parameter_valuess.length; i++) {
		lT_test_designtree_parameter_valuess[i].deleteAndDissociate();
	    }
	    return delete();
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean deleteAndDissociate(org.orm.PersistentSession session)
	    throws PersistentException {
	try {
	    if (getParent() != null) {
		getParent().t_test_designtree.remove(this);
	    }

	    if (getClone() != null) {
		if (getClone().t_test_designtree1.contains(this)) {
		    getClone().t_test_designtree1.remove(this);
		} else {
		    System.out.println("original:" + getClone().getId()
			    + " does not contain clone:" + this.getId());
		}
	    }

	    org.testis.orm.classes.T_test_designtree[] lT_test_designtrees = t_test_designtree
		    .toArray();
	    for (int i = 0; i < lT_test_designtrees.length; i++) {
		lT_test_designtrees[i].setParent(null);
	    }
	    org.testis.orm.classes.T_test_designtree[] lT_test_designtree1s = t_test_designtree1
		    .toArray();
	    for (int i = 0; i < lT_test_designtree1s.length; i++) {
		lT_test_designtree1s[i].setClone(null);
	    }
	    org.testis.orm.classes.T_test_designtree_parameter_values[] lT_test_designtree_parameter_valuess = t_test_designtree_parameter_values
		    .toArray();
	    for (int i = 0; i < lT_test_designtree_parameter_valuess.length; i++) {
		lT_test_designtree_parameter_valuess[i].deleteAndDissociate();
	    }
	    try {
		session.delete(this);
		return true;
	    } catch (Exception e) {
		return false;
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    private java.util.Set this_getSet(int key) {
	if (key == org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_T_TEST_DESIGNTREE) {
	    return ORM_t_test_designtree;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_T_TEST_DESIGNTREE1) {
	    return ORM_t_test_designtree1;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_T_TEST_DESIGNTREE_PARAMETER_VALUES) {
	    return ORM_t_test_designtree_parameter_values;
	}

	return null;
    }

    private void this_setOwner(Object owner, int key) {
	if (key == org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_PARENT) {
	    this.Parent = (org.testis.orm.classes.T_test_designtree) owner;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_CLONE) {
	    this.Clone = (org.testis.orm.classes.T_test_designtree) owner;
	}
    }

    org.orm.util.ORMAdapter _ormAdapter = new org.orm.util.AbstractORMAdapter() {

	public java.util.Set getSet(int key) {
	    return this_getSet(key);
	}

	public void setOwner(Object owner, int key) {
	    this_setOwner(owner, key);
	}
    };
    private int id;
    private Integer elementId;
    private Integer typeId;
    private org.testis.orm.classes.T_test_designtree Parent;
    private Integer rank;
    private org.testis.orm.classes.T_test_designtree Clone;
    private java.util.Set ORM_t_test_designtree = new java.util.HashSet();
    private java.util.Set ORM_t_test_designtree1 = new java.util.HashSet();
    private java.util.Set ORM_t_test_designtree_parameter_values = new java.util.HashSet();

    private void setId(int value) {
	this.id = value;
    }

    public int getId() {
	return id;
    }

    public int getORMID() {
	return getId();
    }

    public void setElementId(int value) {
	setElementId(new Integer(value));
    }

    public void setElementId(Integer value) {
	this.elementId = value;
    }

    public Integer getElementId() {
	return elementId;
    }

    public void setTypeId(int value) {
	setTypeId(new Integer(value));
    }

    public void setTypeId(Integer value) {
	this.typeId = value;
    }

    public Integer getTypeId() {
	return typeId;
    }

    public void setRank(int value) {
	setRank(new Integer(value));
    }

    public void setRank(Integer value) {
	this.rank = value;
    }

    public Integer getRank() {
	return rank;
    }

    public void setParent(org.testis.orm.classes.T_test_designtree value) {
	if (Parent != null) {
	    Parent.t_test_designtree.remove(this);
	}
	if (value != null) {
	    value.t_test_designtree.add(this);
	}
    }

    public org.testis.orm.classes.T_test_designtree getParent() {
	return Parent;
    }

    /**
     * This method is for internal use only.
     */
    private void setORM_Parent(
	    org.testis.orm.classes.T_test_designtree value) {
	this.Parent = value;
    }

    private org.testis.orm.classes.T_test_designtree getORM_Parent() {
	return Parent;
    }

    public void setClone(org.testis.orm.classes.T_test_designtree value) {
	if (Clone != null) {
	    Clone.t_test_designtree1.remove(this);
	}
	if (value != null) {
	    value.t_test_designtree1.add(this);
	}
    }

    public org.testis.orm.classes.T_test_designtree getClone() {
	return Clone;
    }

    /**
     * This method is for internal use only.
     */
    private void setORM_Clone(
	    org.testis.orm.classes.T_test_designtree value) {
	this.Clone = value;
    }

    private org.testis.orm.classes.T_test_designtree getORM_Clone() {
	return Clone;
    }

    private void setORM_T_test_designtree(java.util.Set value) {
	this.ORM_t_test_designtree = value;
    }

    private java.util.Set getORM_T_test_designtree() {
	return ORM_t_test_designtree;
    }

    public final org.testis.orm.classes.T_test_designtreeSetCollection t_test_designtree = new org.testis.orm.classes.T_test_designtreeSetCollection(
	    this,
	    _ormAdapter,
	    org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_T_TEST_DESIGNTREE,
	    org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_PARENT,
	    org.testis.orm.manager.ORMConstants.KEY_MUL_ONE_TO_MANY);

    private void setORM_T_test_designtree1(java.util.Set value) {
	this.ORM_t_test_designtree1 = value;
    }

    private java.util.Set getORM_T_test_designtree1() {
	return ORM_t_test_designtree1;
    }

    public final org.testis.orm.classes.T_test_designtreeSetCollection t_test_designtree1 = new org.testis.orm.classes.T_test_designtreeSetCollection(
	    this,
	    _ormAdapter,
	    org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_T_TEST_DESIGNTREE1,
	    org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_CLONE,
	    org.testis.orm.manager.ORMConstants.KEY_MUL_ONE_TO_MANY);

    private void setORM_T_test_designtree_parameter_values(java.util.Set value) {
	this.ORM_t_test_designtree_parameter_values = value;
    }

    private java.util.Set getORM_T_test_designtree_parameter_values() {
	return ORM_t_test_designtree_parameter_values;
    }

    public final org.testis.orm.classes.T_test_designtree_parameter_valuesSetCollection t_test_designtree_parameter_values = new org.testis.orm.classes.T_test_designtree_parameter_valuesSetCollection(
	    this,
	    _ormAdapter,
	    org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_T_TEST_DESIGNTREE_PARAMETER_VALUES,
	    org.testis.orm.manager.ORMConstants.KEY_T_TEST_DESIGNTREE_PARAMETER_VALUES_DESIGNTREE,
	    org.testis.orm.manager.ORMConstants.KEY_MUL_ONE_TO_MANY);

    public String toString() {
	return toString(false);
    }

    public String toString(boolean idOnly) {
	if (idOnly) {
	    return String.valueOf(getId());
	} else {
	    StringBuffer sb = new StringBuffer();
	    sb.append("T_test_designtree[ ");
	    sb.append("Id=").append(getId()).append(" ");
	    sb.append("ElementId=").append(getElementId()).append(" ");
	    sb.append("TypeId=").append(getTypeId()).append(" ");
	    if (getParent() != null) {
		sb.append("Parent.Persist_ID=")
			.append(getParent().toString(true)).append(" ");

	    } else {
		sb.append("Parent=null ");

	    }
	    sb.append("Rank=").append(getRank()).append(" ");
	    if (getClone() != null) {
		sb.append("Clone.Persist_ID=")
			.append(getClone().toString(true)).append(" ");

	    } else {
		sb.append("Clone=null ");

	    }
	    sb.append("T_test_designtree.size=")
		    .append(t_test_designtree.size()).append(" ");
	    sb.append("T_test_designtree1.size=")
		    .append(t_test_designtree1.size()).append(" ");
	    sb.append("T_test_designtree_parameter_values.size=")
		    .append(t_test_designtree_parameter_values.size())
		    .append(" ");
	    sb.append("]");
	    return sb.toString();
	}
    }
}
